package com.yueke.gemini.utils;
import java.util.concurrent.TimeUnit;

import org.redisson.Redisson;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
/**
 * https://github.com/redisson/redisson/wiki
 * @author qxw
 * 2017年11月22日
 * 
 * redis分布式锁
 */

public class RedissonUtils {

	
	public static void main(String[] args) throws InterruptedException {
		Config config = new Config();
		config.useSingleServer().setAddress("redis://127.0.0.1:6379");
		RedissonClient redissonClient = Redisson.create(config);
		RLock fairLock = redissonClient.getLock("TEST_KEY");
		System.out.println(fairLock.toString());
//		fairLock.lock(); 
		// 尝试加锁，最多等待100秒，上锁以后10秒自动解锁
		boolean res = fairLock.tryLock(100, 10, TimeUnit.SECONDS);
		System.out.println(res);
		fairLock.unlock();
	}
}
